#!/bin/bash

# 检查 .ssh 目录是否存在，如果不存在则创建
if [ ! -d "$HOME/.ssh" ]; then
    echo "--------------------------------"
    echo "ssh 目录不存在"
    echo "--------------------------------"
    echo "创建 .ssh 目录"
    echo "--------------------------------"
    mkdir -p "$HOME/.ssh"
    echo "--------------------------------"
    echo "设置 .ssh 目录权限"
    echo "--------------------------------"
    chmod 700 "$HOME/.ssh"
fi

# 将公钥写入到 authorized_keys 文件中
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDRHfUp2G/uVq5fMUoZFxroKBBWaFki3Ke4t5bTT5O7QmYiFgBCE06Pqu4QslHyAoHISKuFtKERoy9mlQ3vP5xosOUuI4u+361okZhn0xJiXffMCj9SNNl5AN60BE9DeLVowlGYk0d2sJb5+u8fF7n9yyI/FjJgZ6SK/uhvf1A2tu3uY2sI1s4BOnviTT8EWOEqJMAnYvVz/P5fkC7kt6dpqW7KaEZd27xfoIAYZfYUPyCuacTAMagX+M5f9apa+nhymeGfkCB8G+UZTzykFFnN83W6yaTLvfG675rJxnv49QaZkospJnL/QcDJp8TXWQT7R6ixCcg18X1eRk6JgQmj78RAcy0RpfJrogY+n0W8VXupAOznzSDQsrxqO60qUR9J9V94t3KPS6vqiYo8ELAZ/uEc+ubT38Kyb8JBeayxzjhAaBWOfMh2Bs9EmVuS4FKuelRjukwXTcYM8Q/Ht0xkuQHgBvUWTtE6YMMplUGQb1A4vnzYlMd5ny2ebkpnqUc= 86137@laptop2ywh" >> "$HOME/.ssh/authorized_keys"

# 设置 authorized_keys 文件的权限
echo "--------------------------------"
echo "设置 authorized_keys 文件的权限"
echo "--------------------------------"
chmod 600 "$HOME/.ssh/authorized_keys"

echo "--------------------------------"
echo "公钥已成功添加到 authorized_keys 文件中。"
echo "--------------------------------"
